package com.movieproject.src;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.movieproject.daos.MovieDAO;
import com.movieproject.daos.OrderDAO;
import com.movieproject.daos.QueueDAO;
import com.movieproject.daos.ReviewDAO;
import com.movieproject.daos.UserDAO;
import com.movieproject.dataobjects.Movie;
import com.movieproject.dataobjects.Review;
import com.movieproject.dataobjects.User;

@Controller
@Transactional
public class TestController {
	@Autowired
	private MovieDAO movieDAO;

	@Autowired
	private OrderDAO orderDAO;

	@Autowired
	private ReviewDAO reviewDAO;

	@Autowired
	private UserDAO userDAO;


	@Autowired
	private QueueDAO queueDAO;

	@RequestMapping(value = "daotest", method = RequestMethod.GET)
	public ModelAndView daoTest() {
		ModelAndView m = new ModelAndView();

		//create some data objects and add them to the DB. 

		Movie movie = new Movie("Soaring Eagle", "Judy Dench", "An eagle finds a creek.", "Natural History", "someurl", "NC-17", "1988"); 
		movieDAO.updateMovie(movie); 

		User user = new User("Bobby", "McGee", "123 drive st.", "New York", "SD", "90210", "bobbo@gmail.com", "1", "bmcgee", "123456789");
		userDAO.updateUser(user);

		Review review = new Review(movie, user, "sucked. would watch again.", 3);
		reviewDAO.updateReview(review);

		//here we add lists of things to the model, by calling the appropriate DAO

		m.getModelMap().addAttribute("movielist", movieDAO.getAllMovies()); 

		m.getModelMap().addAttribute("orderlist", orderDAO.getAllOrders());

		m.getModelMap().addAttribute("reviewlist", reviewDAO.getAllReviews());

		m.getModelMap().addAttribute("userlist", userDAO.getAllUsers());

//		m.getModelMap().addAttribute("currentUser", userDAO.getUser(1));
//		m.getModelMap().addAttribute("currentUser", userDAO.getUser("kyleb"));

		//queue testing


		ArrayList<Movie> queue = (ArrayList<Movie>) movieDAO.getAllMovies(); //our user really likes movies

		queueDAO.updateUserQueue(user, queue);


		//remove objects from DB
		//movieDAO.deleteMovie(movie);
		//userDAO.deleteUser(user);
		//reviewDAO.deleteReview(review);

		return m;
	}

}
